﻿<Window x:Class="InChatter.Client.WPFClient.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:InChatter.Client.WPFClient.Utility"
        Title="{x:Static rex:Resources.MessageWindow}" Height="600" Width="800"      
        WindowStartupLocation="CenterScreen"
        xmlns:rex="clr-namespace:InChatter.Localization.Properties;assembly=InChatter.Localization"
        Visibility="{Binding WindowStatus,Mode= TwoWay}" >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/InChatter.Client.WPFClient;component/Style/DefaultStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <local:MessageTypeConverter x:Key="messageTypeConverter"></local:MessageTypeConverter>
            <local:BoolVisibilityConverter x:Key="boolVisibilityConverter"></local:BoolVisibilityConverter>
            <local:SenderColorConverter x:Key="senderColorConverter"></local:SenderColorConverter>
            <local:BrushOnlineConverter x:Key="brushOnlineConverter" ></local:BrushOnlineConverter>
            <local:MsgCountVisibilityConverter x:Key="msgCountVisibilityConverter"></local:MsgCountVisibilityConverter>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <GroupBox Grid.Column="0" Header="{x:Static rex:Resources.MessageType}">
            <ListBox ItemsSource="{Binding MessageTypeList}"
                     Name="lbType" ItemContainerStyle="{StaticResource MessageListItemStyle}"
                     SelectedValue="{Binding SelectedType,Mode=TwoWay}"  >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <TextBlock HorizontalAlignment="Left" FontWeight="Bold" FontSize="14" Margin="5" Text="{Binding CategoryName}"/>
                            <Border Background="#fff57052" CornerRadius="5" Visibility="{Binding Count,Converter={StaticResource msgCountVisibilityConverter}}" Width="12" Height="12" VerticalAlignment="Center" HorizontalAlignment="Right" >
                                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontWeight="Bold" Text="{Binding Count}"></TextBlock>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>
        <GroupBox Visibility="{Binding ClientVisibility}" Width="200" Grid.Column="1" Header="{x:Static rex:Resources.ClientList}">
            <ListBox ItemsSource="{Binding Clients}"
                     Name="lbClients" ItemContainerStyle="{StaticResource MessageListItemStyle}"
                     SelectedItem="{Binding SelectedClient,Mode=TwoWay}"
                     >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="5">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock FontSize="16" Text="{Binding ClientName}" />
                                <Border Margin="5,0,0,0" CornerRadius="2" Width="12" Height="12" Background="{Binding IsOnline,Converter={StaticResource brushOnlineConverter}}"></Border>
                            </StackPanel>
                            <Border Background="#fff57052" CornerRadius="5" Visibility="{Binding Count,Converter={StaticResource msgCountVisibilityConverter}}" Width="12" Height="12" VerticalAlignment="Center" HorizontalAlignment="Right" >
                                <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontWeight="Bold" Text="{Binding Count}"></TextBlock>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </GroupBox>
        <GroupBox Grid.Column="2" Header="{x:Static rex:Resources.Message}">
            <Grid Background="WhiteSmoke">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>
                <ListBox Name="lbMessage" Grid.Row="0" HorizontalContentAlignment="Stretch"  ItemContainerStyle="{StaticResource MessageListItemStyle}" ItemsSource="{Binding Path=MessageItems}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="5" TextBlock.FontSize="14">
                                <Grid.RowDefinitions>
                                    <RowDefinition></RowDefinition>
                                    <RowDefinition></RowDefinition>
                                </Grid.RowDefinitions>
                                <StackPanel Grid.Row="0" Orientation="Horizontal">
                                    <TextBlock Name="sender" Foreground="{Binding SenderID,Converter={StaticResource senderColorConverter}}" Text="{Binding Converter={StaticResource messageTypeConverter}}"></TextBlock>
                                    <TextBlock Foreground="{Binding Path=Foreground,ElementName=sender}" Margin="0,0,0,0" Text="{Binding SendTime}"></TextBlock>
                                </StackPanel>
                                <Button Style="{StaticResource DeleteButton}"
                                    Visibility="{Binding IsMouseOver,RelativeSource={RelativeSource AncestorType=ListBoxItem},Converter={StaticResource boolVisibilityConverter}}"
                                    ToolTip="{x:Static rex:Resources.DeleteToolTip}" Command="{Binding DataContext.DeleteMsgCommand,RelativeSource={RelativeSource AncestorType=Window}}" CommandParameter="{Binding ID}"
                                    Grid.Row="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Right" BorderThickness="0" Width="15" Height="15" >
                                </Button>
                                <TextBlock Margin="0,5,0,0" TextWrapping="Wrap" Grid.Row="1" Text="{Binding Content}" HorizontalAlignment="Left"></TextBlock>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <Grid Grid.Row="1" Visibility="{Binding SendBoxVisibility}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="100"></RowDefinition>
                        <RowDefinition Height="35"></RowDefinition>
                    </Grid.RowDefinitions>
                    <RichTextBox PreviewKeyUp="rtbSend_PreviewKeyUp" Name="rtbSend" Margin="0,5" Grid.Row="0"></RichTextBox>
                    <Button Content="{x:Static rex:Resources.SendButton}" Width="80" Height="30" Margin="0,0,15,5" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Click="Send_Click"></Button>
                    <Button Name="btnMode" Width="15" Height="30" Margin="0,0,0,5" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Click="ChangeMode_Click">
                        <Path Data="M 0,0.5 L 9,0.5 L 4.5,6" Fill="SteelBlue"></Path>
                    </Button>
                    <Popup Name="popMode" StaysOpen="False"  PlacementTarget="{Binding ElementName=btnMode}" IsOpen="false">
                        <Border BorderThickness="1" BorderBrush="Silver">
                            <StackPanel Background="White" Name="spMode">
                                <RadioButton Click="RadioButton_Checked" Margin="5,5,5,5" Tag="Enter" Content="{x:Static rex:Resources.EnterToSend}"></RadioButton>
                                <RadioButton Click="RadioButton_Checked" Margin="5,0,5,5" Tag="Ctrl+Enter" Content="{x:Static rex:Resources.CtrlEnterToSend}"></RadioButton>
                            </StackPanel>
                        </Border>
                    </Popup>
                </Grid>
            </Grid>

        </GroupBox>
    </Grid>
</Window>
